{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sentinelsat API"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt\n",
    "api = SentinelAPI('mortcanty','caLvi%27','https://scihub.copernicus.eu/dhus')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "footprint = geojson_to_wkt(read_geojson('/home/mort/Downloads/map.geojson'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "products = api.query(footprint,\n",
    "                     date=('20191001','20191231'),\n",
    "                     platformname='Sentinel-1',\n",
    "                     polarisationmode='VV VH',\n",
    "                     sensoroperationalmode='IW',\n",
    "                     orbitdirection='Descending',\n",
    "                     relativeorbitnumber='154',\n",
    "                     producttype='SLC')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "52934023-2fd1-46b3-8c48-652ded99afa7 S1A_IW_SLC__1SDV_20191201T062242_20191201T062309_030151_0371F4_7552\n",
      "9b2c944b-c8a7-42ce-85f9-2c9c9a907aa5 S1B_IW_SLC__1SDV_20191125T062146_20191125T062214_019080_02401D_E4D4\n",
      "5c32463c-76a1-407e-8624-4e70e79eda70 S1A_IW_SLC__1SDV_20191119T062242_20191119T062310_029976_036BE1_D586\n",
      "5d875e6e-5a6c-479c-8c8c-0c4e78a79880 S1B_IW_SLC__1SDV_20191113T062147_20191113T062215_018905_023A7C_F6A5\n",
      "3b719a18-bc01-4d60-a69c-73bc05e7ffba S1A_IW_SLC__1SDV_20191107T062242_20191107T062310_029801_0365D2_0C6D\n",
      "a32783d8-5e01-40f7-90e3-c3d0f118e80c S1B_IW_SLC__1SDV_20191101T062146_20191101T062214_018730_0234D6_DC3B\n",
      "3f7afdca-c10b-4664-bfd5-741e59873b04 S1A_IW_SLC__1SDV_20191026T062242_20191026T062310_029626_035FA2_BF67\n",
      "bc2e3013-a493-4920-8fe3-31e853b58ca0 S1B_IW_SLC__1SDV_20191020T062147_20191020T062215_018555_022F5A_521D\n",
      "d4709b4f-064d-45ab-8d04-a9f5347398e2 S1A_IW_SLC__1SDV_20191014T062242_20191014T062310_029451_0359A3_0704\n",
      "27aae5a0-f897-42a7-b57d-3644b3a39265 S1B_IW_SLC__1SDV_20191008T062146_20191008T062214_018380_0229FB_AF05\n",
      "44869cf6-f21c-4a1c-acc8-372a7eb18b26 S1A_IW_SLC__1SDV_20191002T062242_20191002T062310_029276_035397_0F54\n"
     ]
    }
   ],
   "source": [
    "for key, value in products.items(): \n",
    "    print(key,value['title'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Downloading: 100%|██████████| 4.71G/4.71G [10:51<00:00, 7.22MB/s]\n",
      "MD5 checksumming: 100%|██████████| 4.71G/4.71G [00:10<00:00, 444MB/s]\n",
      "Downloading: 100%|██████████| 4.73G/4.73G [10:52<00:00, 7.24MB/s]\n",
      "MD5 checksumming: 100%|██████████| 4.73G/4.73G [00:10<00:00, 435MB/s]\n",
      "Downloading: 100%|██████████| 4.71G/4.71G [11:06<00:00, 7.07MB/s] \n",
      "MD5 checksumming: 100%|██████████| 4.71G/4.71G [00:10<00:00, 435MB/s]\n",
      "Downloading: 100%|██████████| 4.62G/4.62G [10:35<00:00, 7.27MB/s]\n",
      "MD5 checksumming: 100%|██████████| 4.62G/4.62G [00:10<00:00, 424MB/s]\n",
      "Downloading: 100%|██████████| 4.91G/4.91G [11:51<00:00, 6.90MB/s]  \n",
      "MD5 checksumming: 100%|██████████| 4.91G/4.91G [00:11<00:00, 426MB/s]\n",
      "Downloading: 100%|██████████| 4.73G/4.73G [10:59<00:00, 7.18MB/s] \n",
      "MD5 checksumming: 100%|██████████| 4.73G/4.73G [00:11<00:00, 402MB/s]\n",
      "Downloading: 100%|██████████| 4.87G/4.87G [11:12<00:00, 7.24MB/s]\n",
      "MD5 checksumming: 100%|██████████| 4.87G/4.87G [00:11<00:00, 433MB/s]\n",
      "Downloading: 100%|██████████| 4.66G/4.66G [10:40<00:00, 7.28MB/s]\n",
      "MD5 checksumming: 100%|██████████| 4.66G/4.66G [00:10<00:00, 440MB/s]\n",
      "Downloading: 100%|██████████| 4.81G/4.81G [11:01<00:00, 7.28MB/s]\n",
      "MD5 checksumming: 100%|██████████| 4.81G/4.81G [00:10<00:00, 441MB/s]\n",
      "Downloading: 100%|██████████| 4.70G/4.70G [10:45<00:00, 7.28MB/s]\n",
      "MD5 checksumming: 100%|██████████| 4.70G/4.70G [00:10<00:00, 430MB/s]\n",
      "Downloading: 100%|██████████| 4.78G/4.78G [10:59<00:00, 7.26MB/s]\n",
      "MD5 checksumming: 100%|██████████| 4.78G/4.78G [00:10<00:00, 438MB/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(OrderedDict([('52934023-2fd1-46b3-8c48-652ded99afa7',\n",
       "               {'id': '52934023-2fd1-46b3-8c48-652ded99afa7',\n",
       "                'title': 'S1A_IW_SLC__1SDV_20191201T062242_20191201T062309_030151_0371F4_7552',\n",
       "                'size': 4707886649,\n",
       "                'md5': '4AD0F3E24436708A873A20DF546AB076',\n",
       "                'date': datetime.datetime(2019, 12, 1, 6, 22, 42, 20000),\n",
       "                'footprint': 'POLYGON((-0.223000 52.388298,-4.023356 52.798100,-3.596228 54.469841,0.358928 54.056137,-0.223000 52.388298))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('52934023-2fd1-46b3-8c48-652ded99afa7')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 12, 1, 15, 55, 1, 578000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 12, 1, 15, 54, 23, 583000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1A_IW_SLC__1SDV_20191201T062242_20191201T062309_030151_0371F4_7552.zip',\n",
       "                'downloaded_bytes': 4707886649}),\n",
       "              ('9b2c944b-c8a7-42ce-85f9-2c9c9a907aa5',\n",
       "               {'id': '9b2c944b-c8a7-42ce-85f9-2c9c9a907aa5',\n",
       "                'title': 'S1B_IW_SLC__1SDV_20191125T062146_20191125T062214_019080_02401D_E4D4',\n",
       "                'size': 4726490835,\n",
       "                'md5': 'D5F311608B5CBB34F5C3A0E583306BA8',\n",
       "                'date': datetime.datetime(2019, 11, 25, 6, 21, 46, 741000),\n",
       "                'footprint': 'POLYGON((0.058731 53.211662,-3.817919 53.623341,-3.382653 55.294342,0.656503 54.878262,0.058731 53.211662))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('9b2c944b-c8a7-42ce-85f9-2c9c9a907aa5')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 11, 25, 13, 32, 1, 670000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 11, 25, 13, 31, 20, 83000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1B_IW_SLC__1SDV_20191125T062146_20191125T062214_019080_02401D_E4D4.zip',\n",
       "                'downloaded_bytes': 4726490835}),\n",
       "              ('5c32463c-76a1-407e-8624-4e70e79eda70',\n",
       "               {'id': '5c32463c-76a1-407e-8624-4e70e79eda70',\n",
       "                'title': 'S1A_IW_SLC__1SDV_20191119T062242_20191119T062310_029976_036BE1_D586',\n",
       "                'size': 4714145251,\n",
       "                'md5': '2701FCD3176F1CB9E3FC2DF1A1ED23B0',\n",
       "                'date': datetime.datetime(2019, 11, 19, 6, 22, 42, 480000),\n",
       "                'footprint': 'POLYGON((-0.222408 52.388264,-4.022612 52.798096,-3.595454 54.469719,0.359528 54.055981,-0.222408 52.388264))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('5c32463c-76a1-407e-8624-4e70e79eda70')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 11, 19, 10, 25, 1, 829000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 11, 19, 10, 24, 20, 593000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1A_IW_SLC__1SDV_20191119T062242_20191119T062310_029976_036BE1_D586.zip',\n",
       "                'downloaded_bytes': 4714145251}),\n",
       "              ('5d875e6e-5a6c-479c-8c8c-0c4e78a79880',\n",
       "               {'id': '5d875e6e-5a6c-479c-8c8c-0c4e78a79880',\n",
       "                'title': 'S1B_IW_SLC__1SDV_20191113T062147_20191113T062215_018905_023A7C_F6A5',\n",
       "                'size': 4617405834,\n",
       "                'md5': 'CDCB7219BE821AE63D298C7B98E65740',\n",
       "                'date': datetime.datetime(2019, 11, 13, 6, 21, 47, 64000),\n",
       "                'footprint': 'POLYGON((0.058298 53.211182,-3.818166 53.622852,-3.382831 55.294106,0.656150 54.878033,0.058298 53.211182))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('5d875e6e-5a6c-479c-8c8c-0c4e78a79880')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 11, 13, 20, 58, 2, 86000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 11, 13, 20, 57, 31, 281000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1B_IW_SLC__1SDV_20191113T062147_20191113T062215_018905_023A7C_F6A5.zip',\n",
       "                'downloaded_bytes': 4617405834}),\n",
       "              ('3b719a18-bc01-4d60-a69c-73bc05e7ffba',\n",
       "               {'id': '3b719a18-bc01-4d60-a69c-73bc05e7ffba',\n",
       "                'title': 'S1A_IW_SLC__1SDV_20191107T062242_20191107T062310_029801_0365D2_0C6D',\n",
       "                'size': 4913282444,\n",
       "                'md5': '339CD46B16E59D401CE8D4842354A8EB',\n",
       "                'date': datetime.datetime(2019, 11, 7, 6, 22, 42, 683000),\n",
       "                'footprint': 'POLYGON((-0.222548 52.388237,-4.022624 52.798042,-3.595544 54.469429,0.359278 54.055717,-0.222548 52.388237))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('3b719a18-bc01-4d60-a69c-73bc05e7ffba')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 11, 7, 12, 33, 3, 728000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 11, 7, 12, 32, 34, 662000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1A_IW_SLC__1SDV_20191107T062242_20191107T062310_029801_0365D2_0C6D.zip',\n",
       "                'downloaded_bytes': 4913282444}),\n",
       "              ('a32783d8-5e01-40f7-90e3-c3d0f118e80c',\n",
       "               {'id': 'a32783d8-5e01-40f7-90e3-c3d0f118e80c',\n",
       "                'title': 'S1B_IW_SLC__1SDV_20191101T062146_20191101T062214_018730_0234D6_DC3B',\n",
       "                'size': 4731081826,\n",
       "                'md5': '374A39AEA346B739DA8190A7A4F1A83C',\n",
       "                'date': datetime.datetime(2019, 11, 1, 6, 21, 46, 936000),\n",
       "                'footprint': 'POLYGON((0.059909 53.211811,-3.816533 53.623516,-3.381305 55.294151,0.657590 54.878048,0.059909 53.211811))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('a32783d8-5e01-40f7-90e3-c3d0f118e80c')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 11, 1, 10, 24, 1, 362000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 11, 1, 10, 23, 6, 849000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1B_IW_SLC__1SDV_20191101T062146_20191101T062214_018730_0234D6_DC3B.zip',\n",
       "                'downloaded_bytes': 4731081826}),\n",
       "              ('3f7afdca-c10b-4664-bfd5-741e59873b04',\n",
       "               {'id': '3f7afdca-c10b-4664-bfd5-741e59873b04',\n",
       "                'title': 'S1A_IW_SLC__1SDV_20191026T062242_20191026T062310_029626_035FA2_BF67',\n",
       "                'size': 4867775203,\n",
       "                'md5': '3AF459B97758D16D514A861CC3CD1413',\n",
       "                'date': datetime.datetime(2019, 10, 26, 6, 22, 42, 589000),\n",
       "                'footprint': 'POLYGON((-0.222807 52.388329,-4.022951 52.798065,-3.595904 54.469700,0.359014 54.056065,-0.222807 52.388329))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('3f7afdca-c10b-4664-bfd5-741e59873b04')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 10, 26, 10, 11, 2, 280000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 10, 26, 10, 10, 34, 148000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1A_IW_SLC__1SDV_20191026T062242_20191026T062310_029626_035FA2_BF67.zip',\n",
       "                'downloaded_bytes': 4867775203}),\n",
       "              ('bc2e3013-a493-4920-8fe3-31e853b58ca0',\n",
       "               {'id': 'bc2e3013-a493-4920-8fe3-31e853b58ca0',\n",
       "                'title': 'S1B_IW_SLC__1SDV_20191020T062147_20191020T062215_018555_022F5A_521D',\n",
       "                'size': 4661131020,\n",
       "                'md5': '42AE6171FB4D429FD8EA05C6FEE3031B',\n",
       "                'date': datetime.datetime(2019, 10, 20, 6, 21, 47, 182000),\n",
       "                'footprint': 'POLYGON((0.059518 53.211487,-3.816774 53.623219,-3.381504 55.293854,0.657228 54.877728,0.059518 53.211487))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('bc2e3013-a493-4920-8fe3-31e853b58ca0')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 10, 20, 10, 43, 0, 262000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 10, 20, 10, 42, 53, 769000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1B_IW_SLC__1SDV_20191020T062147_20191020T062215_018555_022F5A_521D.zip',\n",
       "                'downloaded_bytes': 4661131020}),\n",
       "              ('d4709b4f-064d-45ab-8d04-a9f5347398e2',\n",
       "               {'id': 'd4709b4f-064d-45ab-8d04-a9f5347398e2',\n",
       "                'title': 'S1A_IW_SLC__1SDV_20191014T062242_20191014T062310_029451_0359A3_0704',\n",
       "                'size': 4814322092,\n",
       "                'md5': 'BD4D7A1EE4075F00B7CDEC026768C16D',\n",
       "                'date': datetime.datetime(2019, 10, 14, 6, 22, 42, 609000),\n",
       "                'footprint': 'POLYGON((-0.223906 52.387947,-4.023869 52.797642,-3.596859 54.469288,0.357864 54.055695,-0.223906 52.387947))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('d4709b4f-064d-45ab-8d04-a9f5347398e2')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 10, 14, 9, 58, 1, 868000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 10, 14, 9, 57, 40, 332000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1A_IW_SLC__1SDV_20191014T062242_20191014T062310_029451_0359A3_0704.zip',\n",
       "                'downloaded_bytes': 4814322092}),\n",
       "              ('27aae5a0-f897-42a7-b57d-3644b3a39265',\n",
       "               {'id': '27aae5a0-f897-42a7-b57d-3644b3a39265',\n",
       "                'title': 'S1B_IW_SLC__1SDV_20191008T062146_20191008T062214_018380_0229FB_AF05',\n",
       "                'size': 4704561547,\n",
       "                'md5': 'DBE7B5C7B5E0407925CCA14D65ACC57B',\n",
       "                'date': datetime.datetime(2019, 10, 8, 6, 21, 46, 988000),\n",
       "                'footprint': 'POLYGON((0.059310 53.210690,-3.816776 53.622387,-3.381375 55.293648,0.657199 54.877552,0.059310 53.210690))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('27aae5a0-f897-42a7-b57d-3644b3a39265')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 10, 8, 14, 53, 2, 561000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 10, 8, 14, 52, 47, 877000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1B_IW_SLC__1SDV_20191008T062146_20191008T062214_018380_0229FB_AF05.zip',\n",
       "                'downloaded_bytes': 4704561547}),\n",
       "              ('44869cf6-f21c-4a1c-acc8-372a7eb18b26',\n",
       "               {'id': '44869cf6-f21c-4a1c-acc8-372a7eb18b26',\n",
       "                'title': 'S1A_IW_SLC__1SDV_20191002T062242_20191002T062310_029276_035397_0F54',\n",
       "                'size': 4783521909,\n",
       "                'md5': '3447A5FB33A8A32C0535CBA9D655D90D',\n",
       "                'date': datetime.datetime(2019, 10, 2, 6, 22, 42, 703000),\n",
       "                'footprint': 'POLYGON((-0.224886 52.387814,-4.024736 52.797535,-3.597683 54.469181,0.356919 54.055561,-0.224886 52.387814))',\n",
       "                'url': \"https://scihub.copernicus.eu/dhus/odata/v1/Products('44869cf6-f21c-4a1c-acc8-372a7eb18b26')/$value\",\n",
       "                'Online': True,\n",
       "                'Creation Date': datetime.datetime(2019, 10, 2, 11, 37, 0, 619000),\n",
       "                'Ingestion Date': datetime.datetime(2019, 10, 2, 11, 36, 37, 131000),\n",
       "                'path': '/home/mort/python/EESARDocker/src/imagery/S1A_IW_SLC__1SDV_20191002T062242_20191002T062310_029276_035397_0F54.zip',\n",
       "                'downloaded_bytes': 4783521909})]),\n",
       " OrderedDict(),\n",
       " set())"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "api.download_all(products,directory_path='/home/mort/python/EESARDocker/src/imagery')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
